<?php 
class penugasan_marketing_model extends CI_model{

	function list_marketer_marketing(){
		$this->db->select('*');
		$this->db->from('marketer');
		$this->db->order_by('marketer.id_marketer', 'DESC');
		$q = $this->db->get();
		return $q->result();
	}

	function list_kontak(){
		$this->db->select('*');
		$this->db->from('kontak');
		$q = $this->db->get();
		return $q->result();
	}


	function list_penugasan_marketing(){
		$q = $this->db->query("SELECT *, pm.id_perusahaan as pmid_perusahaan, pm.id_marketer as pmid_marketer
							   FROM penugasan_marketing pm
							   JOIN 
							   perusahaan p ON pm.id_perusahaan=p.id_perusahaan
							   WHERE pm.id_marketer is NULL 
							   ORDER BY pm.id_penugasan_marketing DESC");
		return $q->result();
	}

	function list_penugasan_marketing_search($keyword){
		$q = $this->db->query("SELECT *, pm.id_perusahaan as pmid_perusahaan, pm.id_marketer as pmid_marketer
							   FROM penugasan_marketing pm
							   JOIN 
							   perusahaan p ON pm.id_perusahaan=p.id_perusahaan
							   WHERE pm.id_marketer is NULL AND p.nama_perusahaan LIKE '%$keyword%'
							   ORDER BY pm.id_penugasan_marketing DESC");
		return $q->result();
	}

	function show_penugasan_marketing(){
		$q = $this->db->query("SELECT *, pm.id_perusahaan as pmid_perusahaan, pm.id_marketer as pmid_marketer
							   FROM penugasan_marketing pm
							   JOIN 
							   perusahaan p ON pm.id_perusahaan=p.id_perusahaan
							   JOIN 
							   marketer m ON pm.id_marketer=m.id_marketer
							   WHERE pm.id_marketer IS NOT NULL AND p.status_marketing_perusahaan IN('Belum','Positif','Negatif') 
							   ORDER BY p.status_marketing_perusahaan DESC");
		return $q->result();
	}

	function show_penugasan_marketing_search($keyword){
		$q = $this->db->query("SELECT *, pm.id_perusahaan as pmid_perusahaan, pm.id_marketer as pmid_marketer, p.nama_perusahaan
							   FROM penugasan_marketing pm
							   JOIN 
							   perusahaan p ON pm.id_perusahaan=p.id_perusahaan
							   JOIN 
							   marketer m ON pm.id_marketer=m.id_marketer
							   WHERE pm.id_marketer IS NOT NULL AND p.nama_perusahaan LIKE '%$keyword%'
							   ORDER BY p.status_marketing_perusahaan DESC");
		return $q->result();
	}

	function detail_penugasan_marketing($id){
		$q = $this->db->query("SELECT *, pm.id_perusahaan as pmid_perusahaan, pm.id_marketer as pmid_marketer
							   FROM penugasan_marketing pm
							   JOIN 
							   perusahaan p ON pm.id_perusahaan=p.id_perusahaan
							   JOIN 
							   marketer m ON pm.id_marketer=m.id_marketer
							   WHERE pm.id_penugasan_marketing=$id 
							   ORDER BY pm.id_penugasan_marketing DESC");
		return $q->result();
	}
}
?>